package com.puti.doctor.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.puti.common.log.annotation.Log;
import com.puti.common.log.enums.BusinessType;
import com.puti.doctor.domian.LiveBroadcast;
import com.puti.doctor.service.ILiveBroadcastService;
import com.puti.common.core.web.controller.BaseController;
import com.puti.common.core.web.domain.AjaxResult;
import com.puti.common.core.utils.poi.ExcelUtil;
import com.puti.common.core.web.page.TableDataInfo;

/**
 * 直播管理 直播管理Controller
 *
 * @author puti
 * @date 2021-04-21
 */
@RestController
@RequestMapping("/broadcast")
public class LiveBroadcastController extends BaseController
{
    @Autowired
    private ILiveBroadcastService liveBroadcastService;

    /**
     * 分页
     */
    @GetMapping("/pagination")
    public Page pagination(@RequestParam(value = "pageNum",required = true)int pageNum,
                           @RequestParam(value = "pageSize",required = true)int pageSize){
        return liveBroadcastService.pagination(pageNum, pageSize);
    }


    /**
     * 查询直播管理 直播管理列表
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(LiveBroadcast liveBroadcast)
    {
        startPage();
        List<LiveBroadcast> list = liveBroadcastService.selectLiveBroadcastList(liveBroadcast);
        return getDataTable(list);
    }

    /**
     * 导出直播管理 直播管理列表
     */

    @Log(title = "直播管理 直播管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LiveBroadcast liveBroadcast) throws IOException
    {
        List<LiveBroadcast> list = liveBroadcastService.selectLiveBroadcastList(liveBroadcast);
        ExcelUtil<LiveBroadcast> util = new ExcelUtil<LiveBroadcast>(LiveBroadcast.class);
        util.exportExcel(response, list, "直播管理 直播管理数据");
    }

    /**
     * 查看管理详细信息
     *
     */

    @GetMapping(value = "/{broadcastId}")
    public AjaxResult getInfo(@PathVariable("broadcastId") Long broadcastId)
    {
        return AjaxResult.success(liveBroadcastService.selectLiveBroadcastById(broadcastId));
    }

    /**
     * 新增
     */

    @Log(title = "直播管理 直播管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LiveBroadcast liveBroadcast)
    {
        return toAjax(liveBroadcastService.insertLiveBroadcast(liveBroadcast));
    }

    /**
     * 修改
     */

    @Log(title = "直播管理 直播管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LiveBroadcast liveBroadcast)
    {
        return toAjax(liveBroadcastService.updateLiveBroadcast(liveBroadcast));
    }

    /**
     * 删除直播管理 直播管理
     * 关闭
     */

    @Log(title = "直播管理 直播管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{broadcastIds}")
    public AjaxResult remove(@PathVariable Long[] broadcastIds)
    {
        return toAjax(liveBroadcastService.deleteLiveBroadcastByIds(broadcastIds));
    }
}
